package keke;

import java.text.DecimalFormat;
import java.util.*;

abstract class Person implements Comparable<Person>{
	public String name;
	public int age;
	public boolean gender;
	public Person(String name,int age,boolean gender){
		this.name=name;
		this.age=age;
		this.gender=gender;
	}
	@Override
	public String toString() {
		return name + "-" + age + "-" + gender;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (age != other.age)
			return false;
		if (gender != other.gender)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	public int compareTo(Person person) {
		if(this.name==null&&person!=null)
			return 1;
		if(person.name==null&&this!=null)
			return 1;
		if(this.name==null&&person.name==null)
			return 0;
		if(this.name.equals(person.name))
			return this.age-person.age;
		else
		{
			return this.name.compareTo(person.name);
		}
	}
}

class Student extends Person{
	public String stuNo;
	public String clazz;
	public Student(String name,int age, boolean gender, String stuNo, String clazz){
		super(name, age, gender);
		this.stuNo=stuNo;
		this.clazz=clazz;
	}
	

	public String toString(){
		return "Student:"+super.toString()+"-"+stuNo+"-"+clazz;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(!super.equals(obj)) return false;
		Student other = (Student)obj;
		if (stuNo == null) {
			if (other.stuNo != null)
				return false;
		} else if (!stuNo.equals(other.stuNo))
			return false;
		if(clazz==null){
			if(other.clazz!=null)
				return false;
		}
		else if(!clazz.equals(other.clazz))
			return false;
		return true;
	}
}

class Company{
	public String name;
	public Company(String name){
		this.name=name;
	}
	
	public String toString(){
		return name;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Company other = (Company) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}	
}

class Employee extends Person{
	public Company company;
	public double salary;
	public Employee(String name, int age, boolean gender, Company company, double salary){
		super(name, age, gender);
		this.company=company;
		this.salary=salary;
	}

	public String toString(){
		return "Employee:"+super.toString()+"-"+company+"-"+salary;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		DecimalFormat df=new DecimalFormat("#.#");
		if(!super.equals(other)) 
			return false;
		if (company == null) {
			if (other.company != null)
				return false;
		} else if (!company.equals(other.company))
			return false;
		if (!df.format(salary).equals(df.format(other.salary)))
			return false;
		return true;
	}			
}
public class Main0306 {
	public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        ArrayList<Person>personList=new ArrayList<Person>();
        ArrayList<Student>stuList=new ArrayList<Student>();
        ArrayList<Employee>empList=new ArrayList<Employee>();
        String s1;
        while(in.hasNext()){
        	s1 = in.next();
        	if(s1.equals("s")){
        		Student students=new Student(in.next(),in.nextInt(),in.nextBoolean(), in.next(), in.next());
        		personList.add(students);
        	}
        	else if(s1.equals("e")){
        		String name=in.next();
				int age=in.nextInt();
				boolean gender=in.nextBoolean();
				double salary = in.nextDouble();
				String companyName=in.next();
				Company company=null;
				if(companyName!=null)
				{
					 company=new Company(companyName);
					
				}
				Employee employee=new Employee(name, age, gender, company, salary);
				personList.add(employee);
        	}
        	else{
        		break;
        	}
        }
        Collections.sort(personList);
        for(Person per:personList)
		{
			System.out.println(per);
		}
        s1=in.next();
        if(s1.equals("exit"))
        {
        	in.close();
        	return;
        }
        for(Person person:personList)
		{
			if(person instanceof Student&&!stuList.contains((Student)person))
				stuList.add((Student)person);		
		}
		for(Person person:personList)
		{
			if(person instanceof Employee&&!empList.contains((Employee)person))
				empList.add((Employee)person);	
		}
		System.out.println("stuList");
		for(Person person:stuList)
		{
			System.out.println(person);
		}
		System.out.println("empList");
		for(Person person:empList)
		{
			System.out.println(person);
		}
		in.close();
        }
}
